package com.group02.community.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.group02.community.annotation.Log;
import com.group02.community.enmus.BusinessType;
import com.group02.community.entity.vo.SuggestVO;
import com.group02.community.service.ISuggestService;
import com.group02.community.utils.ResponseResult;
import com.group02.community.utils.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Api
@RestController
public class SuggestController {
@Autowired
private ISuggestService suggestService;

    @ApiOperation("查询全部")
    @GetMapping("/suggests")
    public List<SuggestVO> getAllSuggest(){
        return suggestService.selectAllSuggest();
    }

    @ApiOperation("分页查询")
    @GetMapping("/suggests/page")
    public ResponseEntity<IPage<SuggestVO>> getSuggestPage(Long current,Long size,SuggestVO suggestVO){
        return ResponseEntity.ok(suggestService.getSuggestPage(current,size,suggestVO));
    }

    @ApiOperation("添加")
    @PostMapping("/suggest")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    public ResponseResult<String> addRepair(SuggestVO suggestVO){
        if(suggestVO.getComplaintSuggestType()=="0"){
            suggestVO.setComplaintSuggestType("Suggest");
        }else {
            suggestVO.setComplaintSuggestType("Complaint");
        }
        suggestVO.setCommunityId(1338423709557272577L);
        suggestVO.setComplaintSuggestId(UUIDUtils.getId());
        suggestVO.setUserId(suggestVO.getOwnerId());
        suggestService.addSuggest(suggestVO);
        return  ResponseResult.ok("添加成功");
    }

    @ApiOperation("更新")
    @PutMapping("/suggest")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    public ResponseResult<String> updateRepair(@RequestBody SuggestVO suggestVO){
        suggestService.updateById(suggestVO);
        return ResponseResult.ok("更新成功");
    }
    @ApiOperation("删除")
    @DeleteMapping("/suggest/{complaintSuggestId}")
    public ResponseResult<String> deleteRepair(@PathVariable Long complaintSuggestId){
        suggestService.removeById(complaintSuggestId);
        return ResponseResult.ok("删除成功");
    }
    @ApiOperation("导出Excel")
    @GetMapping("/suggest/download")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    public ResponseEntity<String> downloadExcel(HttpServletResponse response) throws IOException {
        suggestService.downloadExcel(response);
        return ResponseEntity.ok("下载成功");
    }
    }

